﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.SANY.Util;

namespace PMS.SANY.Entity
{
    /// <summary>
    /// 物料信息
    /// </summary>
    public partial class MaterielInfor : BusEntity
    {
        /// <summary>
        /// 物料类型编号(MaterielType.Id)
        /// </summary>
        public string TypeId { set; get; }
        /// <summary>
        /// 物料编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 物料名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 物料全称
        /// </summary>
        public string FullName { get; set; }
        /// <summary>
        /// 物料单位(CF_Enum.Code=Unit)
        /// </summary>
        public string Unit { get; set; }
    }

    public partial class MaterielInfor : BusEntity
    {
        /// <summary>
        /// 物料类型实体
        /// </summary>
        public MaterielType Type { set; get; }

        /// <summary>
        /// 物料规格清单-当前物料有哪些可选规格
        /// </summary>
        public List<MaterielSpec> Specs { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class MaterielInforTypeConfig : BusEntityTypeConfig<MaterielInfor>, IEntityTypeConfiguration<MaterielInfor>
    {
        public override void Configure(EntityTypeBuilder<MaterielInfor> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Type).WithMany(p => p.Materiels).HasForeignKey(p => p.TypeId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.TypeId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.FullName).HasMaxLength(EntityDefinition.DefMiddleColLen).IsRequired();
            builder.Property(p => p.Unit).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("物料信息");
            builder.Property(p => p.TypeId).HasComment("物料类型ID");
            builder.Property(p => p.Code).HasComment("物料编码");
            builder.Property(p => p.Name).HasComment("物料名称");
            builder.Property(p => p.FullName).HasComment("物料全称");
            builder.Property(p => p.Unit).HasComment("物料单位");
            #endregion

            #region 种子数据
            //builder.HasData(new MaterielInfor() { Id = "10", Code="00", Name= "搅拌筒总成", FullName= "搅拌筒总成", TypeId="CP", Unit= "EA", ModifyTime=DateTime.Now, CreateTime=DateTime.Now, Deleted=false, CreateUserId = "1", ModifyUserId = "1" });
            
            //builder.HasData(new MaterielInfor() { Id = "1001", Code = "10", Name = "封头", FullName = "封头总成", TypeId = "YCL", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });

            //builder.HasData(new MaterielInfor() { Id = "10021", Code = "06", Name = "前锥拼板", FullName = "前锥拼板", TypeId = "YCL", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new MaterielInfor() { Id = "10031", Code = "07", Name = "中筒拼板", FullName = "中筒拼板", TypeId = "YCL", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new MaterielInfor() { Id = "10041", Code = "08", Name = "后锥前拼板", FullName = "后锥前拼板", TypeId = "YCL", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new MaterielInfor() { Id = "10051", Code = "09", Name = "后锥拼板", FullName = "后锥拼板", TypeId = "YCL", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });

            //builder.HasData(new MaterielInfor() { Id = "1002", Code = "01", Name = "前锥", FullName = "前锥筒体", TypeId = "XLZJ", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new MaterielInfor() { Id = "1003", Code = "02", Name = "中筒", FullName = "中筒筒体", TypeId = "XLZJ", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new MaterielInfor() { Id = "1004", Code = "03", Name = "后锥前", FullName = "后锥前筒体", TypeId = "XLZJ", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new MaterielInfor() { Id = "1005", Code = "04", Name = "后锥", FullName = "后锥筒体", TypeId = "XLZJ", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });

            //builder.HasData(new MaterielInfor() { Id = "1006", Code = "11", Name = "进料管", FullName = "进料管", TypeId = "YCL", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new MaterielInfor() { Id = "1007", Code = "12", Name = "进料喇叭", FullName = "进料喇叭", TypeId = "YCL", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new MaterielInfor() { Id = "1008", Code = "05", Name = "叶片", FullName = "叶片", TypeId = "YCL", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new MaterielInfor() { Id = "1009", Code = "13", Name = "后挡圈Ⅰ", FullName = "后挡圈Ⅰ", TypeId = "YCL", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new MaterielInfor() { Id = "1010", Code = "14", Name = "后挡圈II", FullName = "后挡圈II", TypeId = "YCL", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new MaterielInfor() { Id = "1011", Code = "15", Name = "滚道", FullName = "滚道", TypeId = "YCL", Unit = "EA", ModifyTime = DateTime.Now, CreateTime = DateTime.Now, Deleted = false, CreateUserId = "1", ModifyUserId = "1" });
            

            #endregion
        }
    }
}
